const baseUrl = 'http://yc.tengshemall.com/index.php/Store/';

const uploadImg = 'http://yc.tengshemall.com/index.php/Store/Goods/carupload_image';

// const key ='VPXBZ-ZUPEP-55VD5-VIDKR-G5R7J-MOFVC';
 
const imgUrl = 'http://yc.tengshemall.com';
const uploadMsg = `
					1. 修改app内更新版本显示下载进度
				`;
const http = ({
	url = '',
	param = {},
	...other
} = {}) => {
	if(url!='Order/notice'&&url!='http://yans.oamis.cn/index/index/yangche'){
		uni.showLoading({
			title: '请求中，请耐心等待..'
		});
	}
	let timeStart = Date.now();
	return new Promise((resolve, reject) => {
		uni.request({
			url: getUrl(url),
			data: param,
			header: {
				// 'content-type': 'application/json' ,// 默认值 ,另一种是 
				"content-type": "application/x-www-form-urlencoded"
				// "content-type": "multipart/form-data"
				
			},
			...other,
			complete: (res) => {
				uni.hideLoading();
				console.log(`耗时${Date.now() - timeStart}`);
				console.log(res.statusCode,"状态码")
				if (res.statusCode >= 200 && res.statusCode < 300) {
					resolve(res.data)
				} else {
					reject(res)
				}
			}
		})
	})
}

const getUrl = (url) => {
	if (url.indexOf('://') == -1) {
		url = baseUrl + url;
	}
	return url
}

// get方法
const _get = (url, param = {}) => {
	return http({
		url,
		param
	})
}
//获取token
const _post = (url, param = {}) => {
	// param['token'] = uni.getStorageSync('token')
	param['store_id'] = uni.getStorageSync('store_id')
	return http({
		url,
		param,
		method: 'post'
	})
	// }
}

const _put = (url, param = {}) => {
	return http({
		url,
		param,
		method: 'put'
	})
}

const _delete = (url, param = {}) => {
	return http({
		url,
		param,
		method: 'put'
	})
}
module.exports = {
	baseUrl,
	_get,
	_post,
	_put,
	_delete,
	uploadImg,
	imgUrl,
	uploadMsg
	// key
}
